package com.bafenyi.zh.bafenyilib.activeWindow;

import android.annotation.SuppressLint;

import com.bafenyi.zh.bafenyilib.util.Enum;
import com.bafenyi.zh.bafenyilib.util.PreferenceUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BFYActiveWindow {


    /**
     * 获取评论、分享是否弹出
     * @return 是否弹出评论、分享弹窗
     * */
    public static Enum.ShowActiveWindowType isShowScoreOrShare(){
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        if(PreferenceUtil.getInt("isScoreShow", 0) < 1){
            PreferenceUtil.put("isScoreShow", 1);
            PreferenceUtil.put("showScoreDate",sdf.format(System.currentTimeMillis()));
            return Enum.ShowActiveWindowType.ShowActiveWindowTypeNone;
        }else if (PreferenceUtil.getInt("isScoreShow", 0) == 1) {
            if(PreferenceUtil.getGapCount(PreferenceUtil.getString("showScoreDate", ""), sdf.format(System.currentTimeMillis())) >= 3){
                if(PreferenceUtil.getInt("isAfterShow", 0) == 1) {
                   //评分
                    PreferenceUtil.put("isScoreShow", 2);
                    PreferenceUtil.put("showScoreDate", sdf.format(System.currentTimeMillis()));
                    PreferenceUtil.put("isAfterShow", 0);
                    return Enum.ShowActiveWindowType.ShowActiveWindowTypeScore;
                }else{
                    PreferenceUtil.put("isAfterShow", 1);
                    return Enum.ShowActiveWindowType.ShowActiveWindowTypeNone;
                }
            }else {
                return Enum.ShowActiveWindowType.ShowActiveWindowTypeNone;
            }
        }else{
            if(PreferenceUtil.getInt("isShowScoreOrShare",0) == 0) {
                if (PreferenceUtil.getGapCount(PreferenceUtil.getString("showScoreDate", ""), sdf.format(System.currentTimeMillis())) >= 7) {
                    if(PreferenceUtil.getInt("isAfterShow", 0) == 1) {
                        //分享
                        PreferenceUtil.put("showShareDate", sdf.format(System.currentTimeMillis()));
                        PreferenceUtil.put("isShowScoreOrShare", 1); // 记录下次得展示分享
                        PreferenceUtil.put("isAfterShow", 0);
                        return Enum.ShowActiveWindowType.ShowActiveWindowTypeShare;
                    }else{
                        PreferenceUtil.put("isAfterShow", 1);
                        return Enum.ShowActiveWindowType.ShowActiveWindowTypeNone;
                    }
                }else {
                    return Enum.ShowActiveWindowType.ShowActiveWindowTypeNone;
                }
            }else{
                if (PreferenceUtil.getGapCount(PreferenceUtil.getString("showShareDate", ""), sdf.format(System.currentTimeMillis())) >= 30) {
                    if(PreferenceUtil.getInt("isAfterShow", 0) == 1) {
                        //评分
                        PreferenceUtil.put("showScoreDate", sdf.format(System.currentTimeMillis()));
                        PreferenceUtil.put("isShowScoreOrShare", 0); // 记录下次得展示评分
                        PreferenceUtil.put("isAfterShow", 0);
                        return Enum.ShowActiveWindowType.ShowActiveWindowTypeScore;
                    }else{
                        PreferenceUtil.put("isAfterShow", 1);
                        return Enum.ShowActiveWindowType.ShowActiveWindowTypeNone;

                    }
                }else {
                    return Enum.ShowActiveWindowType.ShowActiveWindowTypeNone;
                }
            }
        }
    }
}
